home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1279 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  44 lines

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Comma Delimited function wanted
  5. Date: 12 Jan 1996 20:33:06 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Message-ID: <4d6gi2$g4r@news.iag.net>
  8. References: <4d1l42$mb6@voyager.Internex.NET> <4d4gic$p7u@umbc9.umbc.edu>
  9. NNTP-Posting-Host: pm1-orl25.iag.net
  10. X-Newsreader: WinVN 0.99.7
  11.  
  12. In article <4d4gic$p7u@umbc9.umbc.edu>, schlein@umbc.edu says...
  13. <snip>
  14. >#include <stdio.h>
  15. >
  16. >int main (void)
  17. >{
  18. >  char *buffer = "3740067099,914885AC2,P03,5000";  
  19. >  char  field1[20],
  20. >        field2[20],
  21. >        field3[20],
  22. >        field4[20];
  23. >
  24. >  sscanf (buffer, "%[^,],%[^,],%[^,],%s", field1, field2, field3, field4);
  25. >  printf ("field1 = %s\n", field1);
  26. >  printf ("field2 = %s\n", field2);
  27. >  printf ("field3 = %s\n", field3);
  28. >  printf ("field4 = %s\n", field4);
  29. >
  30. >  return (0);
  31. >}
  32.  
  33. This works fine, unless it runs into something like:
  34.  
  35.   char *buffer = "3740067099,,P03,5000";  
  36.  
  37. A strtok based solution will have a similar problem.  A full solution to 
  38. this type of parsing will require a non-standard function (custom code).
  39.  
  40. -- 
  41. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  42. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  43.  
  44.